package com.xmmj.baselibrary.utils.viewadapter.image

import android.widget.ImageView
import androidx.annotation.IdRes
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import java.io.File

@BindingAdapter(value = ["url", "placeholder", "error"], requireAll = false)
fun setImage(imageView: ImageView, url: String?, placeholder: Int, error: Int) {
    Glide.with(imageView.context).load(url).placeholder(placeholder).error(error)
        .into(imageView)
}

@BindingAdapter(value = ["path"], requireAll = false)
fun setImage(imageView: ImageView, path: String?) {
    Glide.with(imageView.context).load(File(path)).into(imageView)
}

@BindingAdapter(value = ["gif"], requireAll = false)
fun setGif(imageView: ImageView, gif: Int) {
    Glide.with(imageView.context).asGif().load(gif).into(imageView)
}

@BindingAdapter(value = ["android:background"], requireAll = false)
fun setBackground(imageView: ImageView, background: Int) {
    imageView.setBackgroundResource(background)
}
